package com.yupi.springbootinit.manager;

import com.yupi.springbootinit.common.ErrorCode;
import com.yupi.springbootinit.exception.BusinessException;
import com.yupi.yucongming.dev.client.YuCongMingClient;
import com.yupi.yucongming.dev.common.BaseResponse;
import com.yupi.yucongming.dev.model.DevChatRequest;
import com.yupi.yucongming.dev.model.DevChatResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AiManager {
    @Autowired
    private YuCongMingClient yuCongMingClient;

    public String doChat(String message, Long modelId){
        // 构造请求参数
        DevChatRequest devChatRequest = new DevChatRequest();

        devChatRequest.setModelId(modelId);
        devChatRequest.setMessage(message);

        log.info("=============================================================请求 message：" + message);

        // 获取响应结果
        BaseResponse<DevChatResponse> response = yuCongMingClient.doChat(devChatRequest);

        log.info("=============================================================响应结果为：" + response.toString());

        if(response == null) {
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "AI 响应错误");
        }

        return response.getData().getContent();
    }
}
